Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: segfault in panic when statically compiled #1552

Merged
merged 1 commit into from
Oct 12, 2024

Conversation

PavelBlinnikov
Copy link
Contributor

In the current state of c3c panic in statically compiled binary leads to segfault.

Test code:

module test;

fn int main(String[] args)
{
    std::core::builtin::panic("test1", "test2", "test3", 31337);
    return 0;
}

Compiled with:

c3c build -z "-static"

Reason: segfault happens because dlclose unloads libc.so.6 in static binaries and funcptr given by dlsym is not valid anymore.

void* handle = libc::dlopen("libc.so.6", libc::RTLD_LAZY);
if (handle)
{
BacktraceFn backtrace_fn = libc::dlsym(handle, "backtrace");
libc::dlclose(handle);
if (backtrace_fn)
{
return backtrace_fn(buffer, size);
}
}

Solution: add RTLD_NODELETE to dlopen which does not allow unloading libc.so.6 in dlclose

void* handle = libc::dlopen("libc.so.6", libc::RTLD_LAZY|libc::RTLD_NODELETE);

@lerno lerno merged commit 6a2957f into c3lang:master Oct 12, 2024
43 checks passed
@lerno
Copy link
Collaborator

lerno commented Oct 12, 2024

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants